package codeRandomThoughts.Test226翻转二叉树;

import codeRandomThoughts.utils.TreeNode;

import java.util.HashMap;

//3刷
public class Solution4 {
    public TreeNode invertTree(TreeNode root) {
        return invert(root);
    }

    public TreeNode invert(TreeNode root) {
        //递归终止条件
        if (root == null) {
            return root;
        }

        //类似于后序遍历
        TreeNode left = invert(root.left);
        TreeNode right = invert(root.right);
        root.left = right;
        root.right = left;
        return root;
    }


}
